﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using FFS.IDAL;
using FFS.DBUtility;

namespace FFS.SQLDAL
{
    public class SystemToolsDAO:ISystemToolsDAO
    {

        #region ISystemTools 成员

        public string GetDatabaseName()
        {
            string databaseName = "";
            string sqlText = " SELECT ISNULL((SELECT TOP 1 Name From Master.dbo.SysDataBases Where DbId=(Select Dbid From Master.dbo.SysProcesses Where Spid = @@spid)),N'') AS databaseName ";

            databaseName = DBHelper.ExecuteScalar(System.Data.CommandType.Text, sqlText, null).ToString().Trim();

            return databaseName;
        }

        public void BackupDatabase(string backupDatabaseFullPath,string input_user)
        {
            string sqlText = "proc_backup_database";
            SqlParameter[] param = { 
                                    new SqlParameter("@backupDirectory",backupDatabaseFullPath),
                                    new SqlParameter("@input_user",input_user)
                                   };
            DBHelper.ExecuteNonQuery(CommandType.StoredProcedure,sqlText,param);
        }

        public void InitSystem(string input_user)
        {
            string sqlText = "proc_init_system";
            SqlParameter[] param = { 
                                    new SqlParameter("@input_user",input_user)
                                   };
            DBHelper.ExecuteNonQuery(CommandType.StoredProcedure, sqlText, param);
        }

        public object VerifyDatabaseLinkStatus()
        {
            string sqlText = " select 1 as _value ";
            return DBHelper.ExecuteScalar(CommandType.Text,sqlText,null);
        }

        #endregion
    }
}
